﻿using System;
using System.Net;
using System.Runtime.Serialization;
using System.Security.Permissions;

namespace Subkismet.Waegis.Client.Components
{
    /// <summary>
    /// Represents exceptions in the Waegis response
    /// </summary>
    [Serializable]
    public sealed class ResponseException : Exception, ISerializable
    {
        #region Fields

        HttpStatusCode _status = 0;

        #endregion

        #region Properties

        public HttpStatusCode HttpStatus
        {
            get
            {
                return this._status;
            }
        }

        #endregion

        #region Public Constructors

        public ResponseException()
        {
        }

        private ResponseException(SerializationInfo info, StreamingContext context)
        {
            _status = (HttpStatusCode)(info.GetValue("Status", typeof(HttpStatusCode)));
        }

        public ResponseException(string message)
            : base(message)
        {
        }

        public ResponseException(string message, Exception innerException)
            : base(message, innerException)
        {
        }

        public ResponseException(string message, HttpStatusCode status)
            : base(message)
        {
            this._status = status;
        }

        #endregion

        #region Private Methods

        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Status", this._status);
            GetObjectData(info, context);
        }

        #endregion
    }
}
